const gulp = require('gulp')
const less = require('gulp-less')
const del = require('del')//npm del
//can i use https://caniuse.com/
const autoprefixer = require('gulp-autoprefixer')
//browserslist https://github.com/ai/browserslist
const cleanCSS = require('gulp-clean-css')
//gulp-clean-css 压缩css

gulp.task('clean', () => {
	del.sync('build')
})

gulp.task('less', () => {
	gulp.src('src/**/*.less')
		.pipe(less())
		.pipe(autoprefixer({
			browsers: ['last 5 version', 'Firefox > 20'],
			cascade: false
		}))
		.pipe(cleanCSS())
		.pipe(gulp.dest('build'))
})


gulp.task('default', ['clean', 'less'], () => {
	console.info('done')
})

gulp.task('watch',()=>{
	const watcher = gulp.watch('src/**/*',['default'])
	watcher.on('change',event=>{
		console.info(`File ${event.path} was ${event.type}`)
	})
})
